namespace Bmz.Laboratory.Workflow.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.InstanceAccesses",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserCode = c.String(maxLength: 50),
                        Status = c.Int(nullable: false),
                        TemplateAccessOject = c.String(maxLength: 50),
                        InstanceNodeId = c.String(maxLength: 50),
                        IsEnable = c.Boolean(nullable: false),
                        CreateUser = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        UpdateUser = c.String(maxLength: 50),
                        UpdateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.InstanceNodes", t => t.InstanceNodeId)
                .ForeignKey("dbo.TemplateAccesses", t => t.TemplateAccessOject)
                .Index(t => t.TemplateAccessOject)
                .Index(t => t.InstanceNodeId);
            
            CreateTable(
                "dbo.InstanceNodes",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 50),
                        Status = c.Int(nullable: false),
                        TemplateNodeCode = c.String(maxLength: 50),
                        FlowdId = c.String(maxLength: 50),
                        IsEnable = c.Boolean(nullable: false),
                        CreateUser = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        UpdateUser = c.String(maxLength: 50),
                        UpdateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.InstanceFlows", t => t.FlowdId)
                .ForeignKey("dbo.TemplateNodes", t => t.TemplateNodeCode)
                .Index(t => t.TemplateNodeCode)
                .Index(t => t.FlowdId);
            
            CreateTable(
                "dbo.InstanceFlows",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 50),
                        Status = c.Int(nullable: false),
                        TemplateFlowCode = c.String(maxLength: 50),
                        IsEnable = c.Boolean(nullable: false),
                        CreateUser = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        UpdateUser = c.String(maxLength: 50),
                        UpdateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.TemplateFlows", t => t.TemplateFlowCode)
                .Index(t => t.TemplateFlowCode);
            
            CreateTable(
                "dbo.TemplateFlows",
                c => new
                    {
                        Code = c.String(nullable: false, maxLength: 50),
                        Name = c.String(maxLength: 50),
                        Type = c.String(maxLength: 50),
                        Description = c.String(maxLength: 200),
                        IsEnable = c.Boolean(nullable: false),
                        CreateUser = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        UpdateUser = c.String(maxLength: 50),
                        UpdateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Code);
            
            CreateTable(
                "dbo.TemplateNodes",
                c => new
                    {
                        Code = c.String(nullable: false, maxLength: 50),
                        Name = c.String(maxLength: 50),
                        Type = c.Int(nullable: false),
                        Description = c.String(maxLength: 200),
                        Url = c.String(maxLength: 200),
                        InRule = c.Int(nullable: false),
                        OutRule = c.Int(nullable: false),
                        PositionLeft = c.Int(nullable: false),
                        PositionTop = c.Int(nullable: false),
                        FlowCode = c.String(maxLength: 50),
                        IsEnable = c.Boolean(nullable: false),
                        CreateUser = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        UpdateUser = c.String(maxLength: 50),
                        UpdateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Code)
                .ForeignKey("dbo.TemplateFlows", t => t.FlowCode)
                .Index(t => t.FlowCode);
            
            CreateTable(
                "dbo.TemplateNodeAccessPermissions",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TemplateNodeCode = c.String(maxLength: 50),
                        TemplateAccessObject = c.String(maxLength: 50),
                        TemplatePermissionCode = c.String(maxLength: 50),
                        IsEnable = c.Boolean(nullable: false),
                        CreateUser = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        UpdateUser = c.String(maxLength: 50),
                        UpdateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.TemplateAccesses", t => t.TemplateAccessObject)
                .ForeignKey("dbo.TemplateNodes", t => t.TemplateNodeCode)
                .ForeignKey("dbo.TemplatePermissions", t => t.TemplatePermissionCode)
                .Index(t => t.TemplateNodeCode)
                .Index(t => t.TemplateAccessObject)
                .Index(t => t.TemplatePermissionCode);
            
            CreateTable(
                "dbo.TemplateAccesses",
                c => new
                    {
                        Oject = c.String(nullable: false, maxLength: 50),
                        Type = c.String(maxLength: 50),
                        IsEnable = c.Boolean(nullable: false),
                        CreateUser = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        UpdateUser = c.String(maxLength: 50),
                        UpdateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Oject);
            
            CreateTable(
                "dbo.TemplatePermissions",
                c => new
                    {
                        Code = c.String(nullable: false, maxLength: 50),
                        Name = c.String(maxLength: 50),
                        IsEnable = c.Boolean(nullable: false),
                        CreateUser = c.String(maxLength: 50),
                        CreateDate = c.DateTime(),
                        UpdateUser = c.String(maxLength: 50),
                        UpdateDate = c.DateTime(),
                    })
                .PrimaryKey(t => t.Code);
            
            CreateTable(
                "dbo.TemplateNodeTemplateNodes",
                c => new
                    {
                        TemplateNode_Code = c.String(nullable: false, maxLength: 50),
                        TemplateNode_Code1 = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => new { t.TemplateNode_Code, t.TemplateNode_Code1 })
                .ForeignKey("dbo.TemplateNodes", t => t.TemplateNode_Code)
                .ForeignKey("dbo.TemplateNodes", t => t.TemplateNode_Code1)
                .Index(t => t.TemplateNode_Code)
                .Index(t => t.TemplateNode_Code1);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.InstanceAccesses", "TemplateAccessOject", "dbo.TemplateAccesses");
            DropForeignKey("dbo.InstanceNodes", "TemplateNodeCode", "dbo.TemplateNodes");
            DropForeignKey("dbo.InstanceFlows", "TemplateFlowCode", "dbo.TemplateFlows");
            DropForeignKey("dbo.TemplateNodeAccessPermissions", "TemplatePermissionCode", "dbo.TemplatePermissions");
            DropForeignKey("dbo.TemplateNodeAccessPermissions", "TemplateNodeCode", "dbo.TemplateNodes");
            DropForeignKey("dbo.TemplateNodeAccessPermissions", "TemplateAccessObject", "dbo.TemplateAccesses");
            DropForeignKey("dbo.TemplateNodes", "FlowCode", "dbo.TemplateFlows");
            DropForeignKey("dbo.TemplateNodeTemplateNodes", "TemplateNode_Code1", "dbo.TemplateNodes");
            DropForeignKey("dbo.TemplateNodeTemplateNodes", "TemplateNode_Code", "dbo.TemplateNodes");
            DropForeignKey("dbo.InstanceNodes", "FlowdId", "dbo.InstanceFlows");
            DropForeignKey("dbo.InstanceAccesses", "InstanceNodeId", "dbo.InstanceNodes");
            DropIndex("dbo.TemplateNodeTemplateNodes", new[] { "TemplateNode_Code1" });
            DropIndex("dbo.TemplateNodeTemplateNodes", new[] { "TemplateNode_Code" });
            DropIndex("dbo.TemplateNodeAccessPermissions", new[] { "TemplatePermissionCode" });
            DropIndex("dbo.TemplateNodeAccessPermissions", new[] { "TemplateAccessObject" });
            DropIndex("dbo.TemplateNodeAccessPermissions", new[] { "TemplateNodeCode" });
            DropIndex("dbo.TemplateNodes", new[] { "FlowCode" });
            DropIndex("dbo.InstanceFlows", new[] { "TemplateFlowCode" });
            DropIndex("dbo.InstanceNodes", new[] { "FlowdId" });
            DropIndex("dbo.InstanceNodes", new[] { "TemplateNodeCode" });
            DropIndex("dbo.InstanceAccesses", new[] { "InstanceNodeId" });
            DropIndex("dbo.InstanceAccesses", new[] { "TemplateAccessOject" });
            DropTable("dbo.TemplateNodeTemplateNodes");
            DropTable("dbo.TemplatePermissions");
            DropTable("dbo.TemplateAccesses");
            DropTable("dbo.TemplateNodeAccessPermissions");
            DropTable("dbo.TemplateNodes");
            DropTable("dbo.TemplateFlows");
            DropTable("dbo.InstanceFlows");
            DropTable("dbo.InstanceNodes");
            DropTable("dbo.InstanceAccesses");
        }
    }
}
